package com.wpw.java8demo;

import org.junit.Before;
import org.junit.Test;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;

/**
 * @Description
 * @ClassName ComparatorTest
 * @Author wupengwei
 * @Date 2022/3/29 18:05
 */
public class ComparatorTest {

    List<Apple> appList;
    String[] colors = {"red","green","yellow"};

    @Before
    public void before() {
        appList = new ArrayList<>();
        Apple app;
        for (int i = 0; i < 20; i++) {
            app = new Apple();
            app.setColor(colors[i%3]);
            app.setWeigth(new Random().nextInt(10));
            appList.add(app);
        }
    }

    @Test
    public void ComparatorTest() {
        System.out.println(appList);
        List<Apple> collect = appList.stream().sorted(Comparator.comparing(Apple::getWeigth)).collect(Collectors.toList());
        System.out.println(appList);
        appList.sort(Comparator.comparing(Apple::getWeigth));
        System.out.println(appList);
        System.out.println(collect);

    }
    @Test
    public void ComparatorTest1() {
        System.out.println("ddd");

    }
}
